package 常见容器;

import java.util.Scanner;

public class 模拟栈 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int[] se = new int[100010];
        int h = 0;
        int t = sc.nextInt();
        while(t-- > 0) {
            String s = sc.next();
            if(s.equals("push")) {
                int x = sc.nextInt();
                se[++h] = x;
            } else if(s.equals("pop")) {
                h--;
            } else if(s.equals("empty")){
                if(h == 0) {
                    System.out.println("YES");
                } else {
                    System.out.println("NO");
                }
            } else if("query".equals(s)){
                System.out.println(se[h]);
            }
        }
    }
}
